import { ref, reactive, onMounted } from 'vue'
import { getAdminList } from '@/api/common/system';

export default function (event:any, type:string) {
    
    const state = ref(0);
    const page = ref(1);
    const pageSize = ref(20);
    const search = ref('');
    const total = ref(0);
    const bage = ref([]);
    const list = ref([]);

    async function adminList(event:any, type:string) {
        try {
            switch(type){
                case 'state':
                    state.value = event;
                    break;
                case 'search': 
                    search.value = event;
                    break;   
                case 'refresh': 
                    search.value = '';
                    state.value = 0;
                    break; 
                case 'page': 
                    page.value = event;
                    break; 
                case 'pageSize': 
                    pageSize.value = event;
                    break;
            }

            let {data} = await getAdminList(page.value, pageSize.value, search.value, state.value);
            // let { total, bage, list } = data;  // 解构会报错（变量重名）
            total.value = data.total;
            bage.value = data.bage;
            list.value = data.list;
          } catch (error) {
            console.log(error)
          }
        
    }

    onMounted(() => { adminList() })

    return { total, bage, list, adminList }
}
